﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAO;
using DTO;

namespace QLDaiLy
{
    public partial class DanhSachCacPhieuThu : XtraUserControl
    {
        public DanhSachCacPhieuThu()
        {
            InitializeComponent();
            LoadDanhDanhSachPhieuThu();
        }
        private void LoadDanhDanhSachPhieuThu()
        {

            List<PhieuThuTienDTO> list = new List<PhieuThuTienDTO>();
            list = PhieuThuTienDAO.LoadDanhDanhSachPhieuThu();
            gridPhieuThuControl.DataSource = list;
        }
        private void repositoryItemPictureDelete_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Bạn muốn xoá hay không ?", "Thông báo", MessageBoxButtons.OKCancel);
            string MaPhieuThu = gridViewDanhSachPhieuThu.GetRowCellValue(gridViewDanhSachPhieuThu.FocusedRowHandle, gridViewDanhSachPhieuThu.Columns["MaPhieuThu"]).ToString();
            string MaDaiLy = gridViewDanhSachPhieuThu.GetRowCellValue(gridViewDanhSachPhieuThu.FocusedRowHandle, gridViewDanhSachPhieuThu.Columns["MaDaiLy"]).ToString();
            int SoTienThu = int.Parse(gridViewDanhSachPhieuThu.GetRowCellValue(gridViewDanhSachPhieuThu.FocusedRowHandle, gridViewDanhSachPhieuThu.Columns["SoTienThu"]).ToString());
            bool kq = PhieuThuTienDAO.deletePhieuThu(MaPhieuThu);
            if (kq == true)
            {
                // MessageBox.Show("Xoá thành công");
                bool kqcapNhatGia = DaiLyDAO.CapNhatSoTienThu(MaDaiLy, SoTienThu);
                if (kqcapNhatGia)
                {
                    LoadDanhDanhSachPhieuThu();
                }
                else
                {
                    MessageBox.Show("GiaTiền chưa được cập nhật");
                }
            }
            else
            {
                MessageBox.Show("Xoá Thất Bại");
            }
        }

        private void gridViewDanhSachPhieuThu_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.IsGetData)
            {
                e.Value = QLDaiLy.Properties.Resources.delete;
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
